
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/crypto-js-3.1.6/crypto-js.js"></script>
<script src="js/crypto-js-3.1.6/md5.js"></script>
<script src="js/crypto-js-3.1.6/aes.js"></script>
<script>
    var dynamic_key = 'abc20304050607081q2w3e4r*1K|j!ta'
    var plaintext = '542#1504你好'
    var ciphertext = '8P7sfCwulZ3IpBNYabY9ArQsLqu0NAHxwUzJTbTw2HM='

     // 一定要utf8转码
    var key = CryptoJS.enc.Utf8.parse(dynamic_key);
    var iv  = CryptoJS.enc.Utf8.parse(dynamic_key.substr(0, 16));

    // 加密
    var ciphertext = CryptoJS.AES.encrypt(
        plaintext,
        key,
        {iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}
    );
    ciphertext = ciphertext.toString()
    console.log("encrypted: ", ciphertext)
    // 解密
    var decrypted = CryptoJS.AES.decrypt(
        ciphertext,
        key,
        {iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}
    );
    var get_property_res = decrypted.toString(CryptoJS.enc.Utf8);// 一定要utf8转码
    console.log('echo: ', get_property_res==plaintext)

</script>
